<template>
  <div class="con">
    <el-container>
      <el-container>
        <el-main style="padding:0;">
          <!-- 放置内容区 -->
          <div class="contbox6_10">
            <p class="titlelist6_10">
              账户管理
              <span style="color: #999;">&nbsp;&nbsp;/&nbsp;&nbsp;</span
              >流水明细
            </p>
            <div class="content">
            <div class="sousuojg6_10" style="overflow: hidden">
              <el-form ref="form" :model="form" label-width="100px">
                <el-form-item label="机构ID">
                  <el-input
                    placeholder="请输入归属机构"
                    v-model="listQuery.oEMName"
                  ></el-input>
                </el-form-item>
                <el-form-item label="归属机构">
                  <el-input
                    placeholder="请输入归属机构"
                    @focus="selectInstitution"
                    v-model="officeName"
                  ></el-input>
                </el-form-item>
                <el-form-item label="机构类型">
                  <el-select
                    v-model="listQuery.officeType"
                    placeholder="请选择机构类型"
                    class="filter-item"
                  >
                    <el-option
                      v-for="item in officeType"
                      :key="item.id"
                      :label="item.label"
                      :value="item.id"
                    ></el-option>
                  </el-select>
                </el-form-item>

                <!-- <el-form-item label="机构名称">
                      <el-input placeholder="请输入机构名称" v-model="listQuery.officeName"></el-input>
                    </el-form-item> -->
                <!--<el-col :span="6">-->
                <!--<el-form-item label="订单号">-->
                <!--<el-input placeholder="请输入订单号" v-model="listQuery.orderCode"></el-input>-->
                <!--</el-form-item>-->
                <!--</el-col>-->
                <el-form-item label="类型">
                  <el-select
                    v-model="listQuery.type"
                    placeholder="请选择操作类型"
                    class="filter-item"
                  >
                    <el-option
                      v-for="item in operType"
                      :key="item.id"
                      :label="item.label"
                      :value="item.id"
                    ></el-option>
                  </el-select>
                </el-form-item>
                <el-form-item label="发生时间">
                  <el-date-picker
                    v-model="timers"
                    value-format="yyyy-MM-dd"
                    style="width: 300px"
                    type="daterange"
                    range-separator="至"
                    start-placeholder="开始日期"
                    end-placeholder="结束日期"
                  ></el-date-picker>
                  <!-- <el-col :span="11"> -->
                  <!-- <el-date-picker
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="开始日期"
                          v-model="listQuery.startDate"
                        ></el-date-picker>
                        <div class="times">-</div>
                        <el-date-picker
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="结束日期"
                          v-model="listQuery.endDate"
                        ></el-date-picker> -->
                  <!-- </el-col>
                      <el-col class="line" :span="2" style="text-align: center;">-</el-col>
                      <el-col :span="11">
                        <el-date-picker
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="结束日期"
                          v-model="listQuery.endDate"
                          style="width: 100%;"
                        ></el-date-picker>
                      </el-col> -->
                </el-form-item>
                <!-- <div
                    style="float: right; margin-right: 20px; margin-top: 10px; text-align: right;"
                  > -->
              </el-form>
            </div>
            <div class="buttons">
              
                  <el-button
                    type="primary"
                    @click="handleSelectLists"
                    >搜索</el-button
                  >
                  <el-button @click="resetTheSearch">重置</el-button>
                  <el-button
                  @click="exportFile"
                  class="butt"
                  type="primary"
                  style="margin-left:40px"
                >
                  批量导出
                </el-button>
            </div>
            <div style="margin-top: 10px;">
              <el-table
                :data="list"
                border
                ref="multipleTable"
                tooltip-effect="dark"
                :header-cell-style="{ background: '#F9FAFC', color: '#222' }"
                stripe
                :row-style="{height:'0px'}"
                :cell-style="{padding:'0px'}"
                style="width: 98%;margin-bottom: 20px; margin-left: 20px;"
                :v-loading="listLoading"
              >
                <el-table-column type="selection" width="55"></el-table-column>
                <el-table-column :span="8" label="机构ID">
                  <template slot-scope="scope">
                    <span>{{ scope.row.officeUid }}</span>
                  </template>
                </el-table-column>
                <el-table-column :span="8" label="机构类型">
                  <template slot-scope="scope">
                    <span>{{
                      (scope.row.officeType == 1 && "普通代理") ||
                        (scope.row.officeType == 0 && "OEM") ||
                        (scope.row.officeType == 2 && "admin")
                    }}</span>
                  </template>
                </el-table-column>
                <el-table-column :span="8" label="机构名称">
                  <template slot-scope="scope">
                    <span>{{ scope.row.officeName }}</span>
                  </template>
                </el-table-column>
                <el-table-column :span="8" label="发生日期">
                  <template slot-scope="scope">
                    <span>{{ scope.row.createDate }}</span>
                  </template>
                </el-table-column>
                <el-table-column :span="8" label="积分数量">
                  <template slot-scope="scope">
                    <span>{{ scope.row.points }}</span>
                  </template>
                </el-table-column>
                <!--<el-table-column :span="8" label="订单号">-->
                <!--<template slot-scope="scope">-->
                <!--<span>{{scope.row.orderCode}}</span>-->
                <!--</template>-->
                <!--</el-table-column>-->
                <el-table-column :span="8" label="操作类型">
                  <template slot-scope="scope">
                    <span>{{
                      scope.row.type == 1
                        ? "购买商品"
                        : scope.row.type == 2
                        ? "购买权益"
                        : ""
                    }}</span>
                  </template>
                </el-table-column>
                <!--<el-table-column :span="8" label="入账状态">-->
                <!--<template slot-scope="scope">-->
                <!--<span>{{scope.row.status}}</span>-->
                <!--</template>-->
                <!--</el-table-column>-->
              </el-table>
              <div style="font-size: 16px;margin-top: 30px">
                
                
                <div
                  v-show="!listLoading"
                  class="pagination-container"
                >
                  <el-pagination
                    background
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :current-page.sync="listQuery.page"
                    :page-sizes="[20, 50, 100]"
                    :page-size="listQuery.number"
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="total"
                  ></el-pagination>
                </div>
              </div>
            </div>
          </div></div>
        </el-main>
      </el-container>
    </el-container>
    <Tree :showType="showType" @func="transmit" />
  </div>
</template>

<script>
import Tree from "../tree/index";
export default {
  name: "shareTheTemplate",
  data() {
    return {
      timers: [],
      showType: false,
      list: null,
      total: null,
      listLoading: false,
      checkedAll: false,
      officeName: "",
      listQuery: {
        oemUid:
          localStorage.getItem("jurisdiction") != 2
            ? localStorage.getItem("uid")
            : undefined, //OEMid          officeUid: undefined,//	机构ID
        officeName: "", //	机构名称
        officeType: "", //	机构类型
        officeUid: "",
        points: "", //积分数量
        type: "", //	类型
        startDate: "", //	开始时间
        endDate: "", //	结束时间
        page: 1, //第几页
        number: 20 //每页几条
      },
      form: {},
      selectTime: [],
      // urltype: this.GLOBAL.httpurl, //请求地址
      multipleSelection: [], //选中的数组
      operType: [
        { label: "购买商品", id: "1" },
        { label: "购买权益", id: "2" }
      ],
      officeType: [
        { label: "OEM", id: "0" },
        { label: "普通代理", id: "1" }
      ],
      sign: localStorage.getItem("jurisdiction") == 2, //最高权限看到的true
      dialogFormTitle: "",
      dialogFormWindows: false,
      rules: {}
    };
  },
  components: {
    Tree
  },
  created() {
    let that = this;
    that.handleSelectList();
  },

  methods: {
    //这里开始
    transmit(data) {
      console.log(data.uid);
      //归属机构的uid
      this.listQuery.officeUid = data.uid;
      //归属机构名字
      this.officeName = data.name;
    },
    //设置取消的
    determine() {
      // alert("执行")
      this.showType = false;
    },

    selectInstitution() {
      this.showType = true;
    },
    //这里结束

    /**
     * @Author： Zhu Liang Fu
     * @Date：2020/7/15
     * @annotation: 全选
     **/
    selAll() {
      if (this.checkedAll) {
        this.list.forEach(row => {
          this.$refs.multipleTable.toggleRowSelection(row);
        });
      } else {
        this.$refs.multipleTable.clearSelection();
      }
    },
    /**
     * @Author： Zhu Liang Fu
     * @Date： 2020/6/10 16:41
     * @annotation： 界面集合获取数据
     **/
    handleSelectList() {
      console.log(this.timers != null);
      if (this.timers != null) {
        if (this.timers.length != 0) {
          this.listQuery.startDate = this.timers[0];
          this.listQuery.endDate = this.timers[1];
        }
      }else{
        this.listQuery.startDate = ""
          this.listQuery.endDate = ""
      }
      this.listQuery.officeUid = this.listQuery.oEMName;
      this.listQuery.officeName = this.officeName;
      let that = this;
      that.listLoading = true;
      that
        .axios({
          //axios请求
          method: "POST",
          url: "/api/points/pointsDetail",
          // headers: { "Content-Type": "application/json;charset=utf-8" },
          data: that.listQuery
        })
        .then(res => {
          if (res.data.code == "0000") {
            that.list = res.data.data;
            that.total = res.data.total;
            that.listLoading = false;
          } else {
            that.listLoading = false;
            layer.open({
              content: res.data.msg,
              skin: "msg",
              time:  2, //1秒后自动关闭
            });
          }
        });
    },
    /**
     * @Author： Zhu Liang Fu
     * @Date： 2020/6/10 17:57
     * @annotation： 分页
     **/
    handleSizeChange(val) {
      let that = this;
      that.listQuery.number = val;
      that.listQuery.page = 1;
      that.handleSelectList();
    },
    handleSelectLists() {
      let that = this;
      that.listQuery.page = 1;
      that.handleSelectList();
    },
    /**
     * @Author： Zhu Liang Fu
     * @Date： 2020/6/10 17:57
     * @annotation： 分页
     **/
    handleCurrentChange(val) {
      let that = this;
      that.listQuery.page = val;
      that.handleSelectList();
    },

    /**
     * @Author： Zhu Liang Fu
     * @Date： 2020/6/10 16:41
     * @annotation：  时间格式化
     **/
    timeData(e) {
      let that = this;
      if (e) {
        that.listQuery.startDate = e[0];
        that.listQuery.endDate = e[1];
      } else {
        that.listQuery.startDate = undefined;
        that.listQuery.endDate = undefined;
      }
    },

    /**
     * @author: Zhu Liangfu
     * @Description: 导出模板
     * @date:2020/6/11   20:44
     */
    exportFile() {
      let that = this;
      that
        .axios({
          method: "POST",
          url: "api/account/transactionsList/excel/export",
          headers: { "Content-Type": "application/json;charset=utf-8" },
          data: that.listQuery,
          responseType: "arraybuffer"
        })
        .then(res => {
          let blob = new Blob([res.data], {
            type: "application/vnd.ms-excel;charset=utf-8"
          });
          var link = document.createElement("a");
          link.href = window.URL.createObjectURL(blob);
          let date = new Date();
          link.download =
            "流水明细列表" +
            date.getFullYear() +
            (date.getMonth() < 10 ? "0" + date.getMonth() : date.getMonth()) +
            (date.getDate() < 10 ? "0" + date.getDate() : date.getDate()) +
            (date.getHours() < 10 ? "0" + date.getHours() : date.getHours()) +
            (date.getMinutes() < 10
              ? "0" + date.getMinutes()
              : date.getMinutes()) +
            (date.getSeconds() < 10
              ? "0" + date.getSeconds()
              : date.getSeconds());
          link.click();
        })
        .catch(e => {
        });
    },

    /**
     * @Author： Zhu Liang Fu
     * @Date： 2020/6/10 17:50
     * @annotation： 重置查询条件
     **/
    resetTheSearch() {
      let that = this;
      this.officeName = "";
      that.listQuery = {
        oemUid:
          localStorage.getItem("jurisdiction") != 2
            ? localStorage.getItem("uid")
            : undefined, //OEMid          officeUid: undefined,//	机构ID
        officeName: undefined, //	机构名称
        officeType: undefined, //	机构类型
        orderCode: undefined, //	订单号
        operType: undefined, //	操作类型
        startDate: "", //	开始时间
        endDate: "", //	结束时间
        page: 1, //第几页
        number: 20 //每页几条s
      };
      that.timers = [];
      that.handleSelectList();
    }
  }
};
</script>

<style scoped>
.con {
  position: relative;
}
/* 单独样式 */
.contbox6_10 {
   width: 100%;
  /*  height: 87.5vh; */
  overflow-x: auto;
  box-sizing: border-box;
  float: left;
}


.fileList {
  display: inline-block;
  border-style: solid dotted dashed double;
  padding: 8px 8px 8px 8px;
  text-align: center;
}
.times {
  width: 20px;
  display: inline-block;
  text-align: center;
}
.boxer {
  /* padding-right: 10px; */
  /* float: right; */
}
.buttons > .el-button {
  width: 32px;
  width: 100px;
  float: left;
}
</style>
